/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 */

package com.xci.edu.core.api;

import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.core.BaseController;
import com.github.lvyanyang.core.BoolResult;
import com.github.lvyanyang.core.Const;
import com.github.lvyanyang.core.PageList;
import com.github.lvyanyang.core.XCI;
import com.xci.edu.core.entity.EduPlan;
import com.xci.edu.core.filter.EduPlanFilter;
import com.xci.edu.core.service.EduPlanService;
import com.github.lvyanyang.model.*;
import com.xci.edu.core.service.EduStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 培训计划接口
 * @author 张谦 zhangqian@xci96716.com
 * @since 2020-11-25 09:35:56
 */
@Api(tags = "培训计划接口")
@Authorize
@RestController
@RequestMapping(value = "/api/core/eduPlan", produces = Const.PROJSON)
public class EduPlanApiController extends BaseController {
    /** 培训计划服务 */
    @Resource private EduPlanService eduPlanService;
    /** 学员服务 */
    @Resource private EduStudentService eduStudentService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新建培训计划")
    @Authorize(code = "core.eduPlan.insert")
    @PostMapping("/insert")
    public BoolResult insert(@RequestBody EduPlan entity) {
        return eduPlanService.insert(entity);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "修改培训计划")
    @Authorize(code = "core.eduPlan.update")
    @PostMapping("/update")
    public BoolResult update(@RequestBody EduPlan entity) {
        return eduPlanService.update(entity);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "修改培训计划状态")
    @Authorize(code = "core.eduPlan.updateStatus")
    @PostMapping(value = "/updateStatus")
    public BoolResult updateStatus(@RequestBody IdsStatusBody body) {
        eduPlanService.updateStatus(body.getIds(), body.getStatus());
        return BoolResult.success();
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主键字符串删除培训计划")
    @Authorize(code = "core.eduPlan.delete")
    @PostMapping(value = "/delete")
    public BoolResult delete(@RequestBody IdsBody body) {
        return eduPlanService.delete(body.getIds());
    }

    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "根据主键查询单个培训计划")
    @Authorize(code = "core.eduPlan.select")
    @PostMapping("/selectById")
    public BoolResult<EduPlan> selectById(@RequestBody IdBody body) {
        return BoolResult.success(eduPlanService.selectById(body.getId()));
    }

    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "查询培训计划分页列表")
    @Authorize(code = "core.eduPlan.select")
    @PostMapping("/selectPageList")
    public BoolResult<PageList<EduPlan>> selectPageList(@RequestBody EduPlanFilter filter) {
        return BoolResult.success(eduPlanService.selectPageList(filter));
    }

    @ApiOperationSupport(order = 8, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "查询培训计划列表")
    @Authorize(code = "core.eduPlan.select")
    @PostMapping("/selectList")
    public BoolResult<List<EduPlan>> selectList(@RequestBody EduPlanFilter filter) {
        return BoolResult.success(eduPlanService.selectList(filter));
    }

    @ApiOperationSupport(order = 9, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "导出培训计划列表")
    @Authorize(code = "core.eduPlan.export")
    @PostMapping(value = "/export", produces = {Const.PROOCTET, Const.PROJSON})
    public void export(@RequestBody EduPlanFilter filter) {
        XCI.exportExcel(eduPlanService.selectList(filter), EduPlan.class, "培训计划列表");
    }

    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "设置培训计划")
    @Authorize(code = "core.eduPlan.setPlan")
    @PostMapping("/setPlanUpdate")
    public BoolResult setPlanUpdate(@RequestBody String ids,@RequestBody String planId,@RequestBody String planName) {
        return eduStudentService.setPlanUpdate(ids,Long.valueOf(planId),planName);
    }
    //@ApiOperationSupport(order = 10)
    //@ApiOperation(value = "获取培训计划导出字段")
    //@PostMapping(value = "/exportNames")
    //public BoolResult<List<String>> exportNames() {
    //    return BoolResult.success(XCI.getExcelFiledNames(EduPlan.class));
    //}
}